<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/04/11 20:58:15 $)
// $RCSfile: report_worksummary.php,v $ : $Revision: 1.3 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}


$template->assign("calendar", true);

$interface->staffHeader($_SWIFT["language"]["tickets"]." &gt; ".$_SWIFT["language"]["reports"], 2);

renderTicketTree();
$interface->staffNavBar('<a href="index.php?_m=tickets&_a=manage" title="'.$_SWIFT["language"]["tickets"].'">'.$_SWIFT["language"]["tickets"].'</a> &raquo; '.'<a href="index.php?_m=tickets&_a=reports&type=worksummary" title="'.$_SWIFT["language"]["reports"].'">'.$_SWIFT["language"]["reports"].'</a> &raquo; '.'<a href="index.php?_m=tickets&_a=reports&type=worksummary" title="'.$_SWIFT["language"]["repworksummary"].'">'.$_SWIFT["language"]["repworksummary"].'</a>', "", 2);

printInfoBox($infomessage);
printErrorBox($errormessage);

// Generate Report
if ($_POST["step"] == 1)
{
	$_datefrom = getCalendarDateline($_POST["datefrom"]);
	$_dateto = getCalendarDateline($_POST["dateto"]);
	if (empty($_POST["dateto"]))
	{
		$_dateto = $_datefrom+86400;
	}
	$_daydiff = $_dateto-$_datefrom;
	if ($_daydiff < 0)
	{
		echo $_SWIFT["language"]["reporterror"];
		exit;
	} else if ($_daydiff == 0) {
		$_daynum = 1;
	} else {
		$_daynum = ceil($_daydiff/86400)+1;
	}

	foreach ($_POST["staffidlist"] as $key=>$val)
	{
		$_logs = loadAuditLogs($val, $_datefrom, $_dateto);

		for ($ii=0; $ii<$_daynum; $ii++)
		{
			$_daydateline = $_datefrom+($ii*86400);
			echo renderDayReport(date("d-m-Y", $_daydateline), $_logs, $val);
		}
	}

	$template->assign("backurl", "index.php?_m=tickets&_a=reports&type=worksummary");

	$interface->staffFooter();
	exit;
}

printFormStart();
printMainTableHeader($_SWIFT["language"]["repworksummary"]);

$options = array();
$index = 0;
$dbCore->query("SELECT `staffid`, `fullname`, `username` FROM `". TABLE_PREFIX ."staff` ORDER BY `staffid` ASC;");
while ($dbCore->nextRecord())
{
	$options[$index]["title"] = $dbCore->Record["fullname"];
	$options[$index]["value"] = $dbCore->Record["staffid"];
	$options[$index]["checked"] = iif($dbCore->Record["staffid"]==$_SWIFT["staff"]["staffid"], true, false);
	$index++;
}
printCheckboxListRow("staffidlist", $_SWIFT["language"]["repstafflist"], $_SWIFT["language"]["desc_repstafflist"], $options);

printDateRow("datefrom", $_SWIFT["language"]["repdatefrom"], $_SWIFT["language"]["desc_repdatefrom"], date("d/m/Y", DATENOW));

printDateRow("dateto", $_SWIFT["language"]["repdateto"], $_SWIFT["language"]["desc_repdateto"], date("d/m/Y", DATENOW));

printSubmitRow($_SWIFT["language"]["repgenerate"]);

printMainTableFooter();

addHiddenField("_m", "tickets");
addHiddenField("_a", "reports");
addHiddenField("type", "worksummary");
addHiddenField("step", "1");
printFormEnd();

$template->assign("backurl", "index.php?_m=tickets&_a=manage");

$interface->staffFooter();
?>